package jzqb.service.impl;

import haha.life.common.SysTool;
import jzqb.bo.VisitBo;
import jzqb.common.Result;
import jzqb.dao.VisitDao;
import jzqb.service.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2020-09-22
 */
@Service
public class VisitServiceImpl implements VisitService {
    @Autowired
    VisitDao  visitDao;

    @Override
    public Result visitIncrease(VisitBo visitBo) {
        // 1、 先进行查询
        VisitBo visitBoResult = visitDao.selectVisit(visitBo);
        Boolean finalResult =false;
        if (visitBoResult==null){
            String overallId ="";
            //如果为null 进行insert
             if(visitBo.getDbTable().equals(SysTool.QBBK_METADATA) ||visitBo.getDbTable().equals(SysTool.QBCG_METADATA) ||visitBo.getDbTable().equals(SysTool.QBZS_METADATA) ||visitBo.getDbTable().equals(SysTool.QBZY_METADATA)){
                 String[] result = visitBo.getDbTable().split("_");
                 visitBo.setDbCode(result[0]);
                 overallId = visitBo.getDbTable()+"_"+visitBo.getSysID();
                 visitBo.setOverallid(overallId);
                 visitBo.setBrowse(1);
             }else{
                 String[] result = visitBo.getDbTable().split("LAST");
                 visitBo.setDbCode(result[0]);
                 overallId = visitBo.getDbTable()+"_"+visitBo.getFileName();
                 visitBo.setOverallid(overallId);
                 visitBo.setBrowse(1);
             }
            finalResult = visitDao.insertVisit(visitBo);
        }else {
            //拿出数字来进行+1
            visitBoResult.setBrowse(visitBoResult.getBrowse()+1);
            finalResult=  visitDao.updateVisit(visitBoResult);
        }
        if (finalResult){
            return  Result.succ("success");
        }else {
            return Result.fail("fail");
        }
    }
}